package tests;

import contaKM2012.ContaKmWithDisplay;
import display2012.*;
import exceptions.InconsistentValueException;
import interfaces.*;
import it.unibo.baseEnv.basicFrame.EnvFrame;
import it.unibo.is.interfaces.IBasicEnvAwt;

public class ContaKmDisplayInheritTest extends ContaKmTest {
	protected IDisplay ckmDisplay;

	public void setUp() throws Exception {
		super.setUp();
		configure();
	}

	public void testCreation() {
		super.testOnCreate();
	}

	public void testInc() throws InconsistentValueException {
		super.testInc();
	}

	public void testLimit() throws InconsistentValueException {
		super.testIncAtLimit();
	}

	protected void configure() throws InconsistentValueException {
		initDisplay();
		configureTheEntity();
	}

	protected void initDisplay() { // TODO
		IBasicEnvAwt env = new EnvFrame("ContaKm2012");
		// env.initNoFrame(); //does not show the frame
		env.init();
		env.writeOnStatusBar("ContaKm2012" + " | working ... ", 14);
		ckmDisplay = new DisplayGuiContaKm(env);
	}

	public ContaKmDisplayInheritTest(String arg0) {
		super(arg0);
	}

	protected void configureTheEntity() throws InconsistentValueException { // TODO
		ckm = new ContaKmWithDisplay(ckmDisplay);
	}

	protected String toDisplayStr(int v) {
		String vs = "" + v;
		while (vs.length() < 6)
			vs = "0" + vs;
		return vs;
	}

	protected boolean invariant(IContaKm contaKm) {
		// System.out.println("invariant with display");
		return super.invariant() && newCond((IContaKmWithDisplay) contaKm);
	}

	protected boolean newCond(IContaKmWithDisplay contaKm) {
		// System.out.println("newCond");
		return contaKm.getDisplayedVal().equals(toDisplayStr(contaKm.getVal()));
	}
}